package com.lu.pojo.reflection;

/**
 *
 * @author luzhenfang
 * @date 2020 05 24
 * @description 测试 class 类创建方式
 */
public class TestClass {
    public static void main(String[] args) {
        // 1. 通过对象获得
        Person person = new Person();
        Class c1 = person.getClass();
        System.out.println(c1.hashCode());
        // 2. 通过 forName获得
        try {
            Class<?> c2 = Class.forName("com.lu.pojo.reflection.Person");
            System.out.println(c2.hashCode());
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        // 3. 通过类名.class 获得
        Class c3 = Person.class;
        System.out.println(c3.hashCode());
        // 4. 基本类型的包装类都有一个 TYPE属性
        Class<Integer> type = Integer.TYPE;
        System.out.println(type);
        // 获得 父类
        Class superclass = c1.getSuperclass();
        System.out.println(superclass.getName());
    }
}



class Person{
    public String name;

    public Person() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

class Student extends Person{
    public Student(){
        this.name="学生";
    }
}
